'use strict';
/**
 * 角色权限管理Service
 */
app.service('InfoSetService', 
['$http', '$q',
function ($http) {
	this.gridOptions = function(url){
		var _gridWidth = 512;
		var _columnWidth = _gridWidth / 3;
		if(!url){
			url = "/infoType/showRoles"
		}
		return {
			//height: getGridHeight(),
			url: ISS.getPath(url),
			dataType: 'json',
			colModel : [
				{display: 'id', name : 'id', width : 50,hide: true},
				{display: 'role.name', name : 'name', width : _columnWidth},
				{display: 'common.remark', name : 'description', width : _columnWidth},
				{display: 'common.createTime', name : 'createTime', width : _columnWidth},
			],
            isDragCol: true,
			usepager: true,
			showcheckbox: true,
			rp: 10
		};
	}
	
	//根据id查找消息类型
	this.selectInfoType = function(infoType){
		return $http.post(
				ISS.getPath('/infoType/selectInfoType'),
				infoType,
				{contentType: 'json'}
			).then(function(resp){
				return resp.data;
			});
	}
	
	//修改消息类型信息
	this.updateInfoType = function(infoType){
		return $http.post(
				ISS.getPath('/infoType/updateInfoType'),
				infoType,
				{contentType: 'json'}
			).then(function(resp){
				return resp.data;
			});
	}
	
	//新增消息类型信息
	this.addInfoType = function(infoType){
		return $http.post(
				ISS.getPath('/infoType/addInfoType'),
				infoType,
				{contentType: 'json'}
			).then(function(resp){
				return resp.data;
			});
	}
	
	//根据节点ID删除节点
	this.delInfoType = function(infoTypeId){
		return $http.post(
				ISS.getPath('/infoType/delInfoType/'+infoTypeId)
			).then(function(resp){
				return resp.data;
			});
	}
	
	//添加角色到消息类型
	this.infoTypeAddRole = function(params){
		return $http.post(
				ISS.getPath('/infoType/addRole/'),
				params,
				{contentType: 'json'}
			).then(function(resp){
				return resp.data;
			});

	}
	
	//从消息类型中移出角色
	this.removeRole = function(data){
    	return $http.post(
				ISS.getPath('/infoType/removeRole'),
				data,
				{contentType: 'json'}
			).then(function(resp){
				return resp.data;
			});
    }
/*	//查找当前消息类型下的角色
	this.showRoles = function(infoTypeId){
		this.gridOptions
		vm.options = InfoSetService.gridOptions('/infoType/selectInfoType/'+infoTypeId);
		return $http.post(
				ISS.getPath('/infoType/selectInfoType/'+infoTypeId),
				infoType,
				{contentType: 'json'}
			).then(function(resp){
				return resp.data;
			});
	}*/
	
	
	this.initUpdateRole = function(roleId){
		return $http.post(
				ISS.getPath('/role/get/'+roleId)
			).then(function(resp){
				return resp.data;
			});
	}
	this.updateRole = function(role){
		return $http.post(
				ISS.getPath('/role/update'),
				role,
				{contentType: 'json'}
			).then(function(resp){
				return resp.data;
			});
	}
	this.deleteRole = function(data){
		return $http.post(
					ISS.getPath('/role/del/'+ data.id + '/' + data.name)
				).then(function(resp){
					return resp.data;
				});	
	}
}]);